package com.foreknow.service.impl;

import com.foreknow.dao.impl.AdminDaoImpl;
import com.foreknow.db.DBManager;
import com.foreknow.model.Admin;
import com.foreknow.service.AdminService;

import java.sql.Connection;
import java.sql.SQLException;

public class AdminServiceImpl implements AdminService {
    @Override
    public Admin isValidate(String username, String password) {
        //创建DBManager对象
        DBManager dbManager=DBManager.getInstance();
        //调用getConnection方法连接数据库驱动
        Connection conn=dbManager.getConnection();
        AdminDaoImpl adminDao=new AdminDaoImpl();
        //注入数据库连接
        adminDao.setConnection(conn);
        //初始化
        Admin admin=null;
        try {
            //传递给sql语句值 并将查询到的数据赋值给admin
            admin = adminDao.isCheckLogin(username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return admin;
    }

    /**
     * 查询所有用户名
     * @return
     */
    @Override
    public boolean getName(String username) {
        DBManager dbManager = DBManager.getInstance();
        Connection conn = dbManager.getConnection();
        AdminDaoImpl adminDao=new AdminDaoImpl();
        adminDao.setConnection(conn);
        //先初始化
        boolean is=false;
        is=adminDao.selectNameAll(username);
        return is;
    }
}
